import { createRouter, createWebHistory } from 'vue-router'
import { APP_NAME } from '@/config'

export const routes = [
  {
    path: '/',
    redirect: '/commandCenter'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login/index.vue'),
  },
  {
    path: '/commandCenter',
    name: 'CommandCenter',
    component: () => import('@/views/CommandCenter/index.vue'),
    meta: {
      isMenu: true,
      title: '指挥调度中心',
    }
  },
  {
    path: '/activityManage',
    name: 'ActivityManage',
    component: () => import('@/views/ActivityManage/index.vue'),
    meta: {
      isMenu: true,
      title: '安保活动管理',
    }
  },
  {
    path: '/dutyManage',
    name: 'DutyManage',
    component: () => import('@/views/DutyManage/index.vue'),
    meta: {
      isMenu: true,
      title: '安保任务管理',
    }
  },
  {
    path: '/systemSetting',
    name: 'SystemSetting',
    component: () => import('@/views/SystemSetting/index.vue'),
    meta: {
      isMenu: true,
      title: '系统配置管理',
    }
  },
  {
    path: '/element',
    name: 'Element',
    component: () => import('@/views/Element/index.vue')
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
  next();
})

router.afterEach((to, from) => {
  const pageTitleSuffix = to.meta && to.meta.title ? `- ${to.meta.title}` : '';
  document.title = `${APP_NAME}${pageTitleSuffix}`;
})

export default router
